package visualizer;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class Node {

	private String nodeName;
	private String id;
	private List<NodeField> fields;
	private String style = null;
	private ArrayList<String> orderIDs;
	private boolean deleted;
	//CHRISTIAN
	private boolean isMethod;
	private boolean isStaticMethod;
	private boolean isStackFrameMethod;
	private String methodReturnType;
	private List<Node> stackMethods;
	
	public Node() {
		fields = new ArrayList<NodeField>();
		orderIDs = new ArrayList<String>();
	}
	
	public ArrayList<String> getLines() {
		return this.orderIDs;
	}
	public void setOrderIDs(ArrayList<String> list) {
		this.orderIDs = list;
	}
	public void addOrderID(String s) {
		this.orderIDs.add(s);
	}
	public String getNodeName() {
		return nodeName;
	}
	public void setNodeName(String nodeName) {
		this.nodeName = nodeName;
	}
	public String getId() {
		return id;
	}
	public String getShortId() {
		return id.substring(id.indexOf("=")+1, id.indexOf(")"));
	}
	public void setId(String id) {
		this.id = id;
	}
	public List<NodeField> getFields() {
		return fields;
	}
	public void setFields(List<NodeField> fields) {
		this.fields = fields;
	}
	public void addField(NodeField field) {
		this.fields.add(field);
	}
	public String getStyle() {

		if(style == null) {
			throw new KovidaException("Style is not set.");
		}
		return style;
	}
	public void setStyle(String style) {
		this.style = style;
	}
	public boolean hasOrderId(String orderID) {
		return orderIDs.contains(orderID);
	}
	public boolean isDeleted() {
		return this.deleted;
	}
	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}
	//CHRISTIAN:
	public boolean isMethod() {
		return isMethod;
	}

	public List<Node> getStackMethods() {
		return stackMethods;
	}

	public void setStackMethods(List<Node> stackMethods) {
		this.stackMethods = stackMethods;
	}

	//CHRISTIAN
	public void setMethod(boolean isMethod) {
		this.isMethod = isMethod;
	}
	
	//CHRISTIAN
	public boolean containsArgumentField(){
		boolean tmp = false;
		for (NodeField field : getFields()) {
			if(field.isArgument())
				tmp = true;
		}
		return tmp;
	}

	@Override
	public String toString() {
		String s = "";
		s += getClass()+System.getProperty("line.separator");
		s += "Classname: " + this.getNodeName()+System.getProperty("line.separator");
		s += "Id: " + this.getId()+System.getProperty("line.separator");
		s += "ShortId: " + this.getShortId()+System.getProperty("line.separator");
		s += "Style: " + this.getStyle()+System.getProperty("line.separator");
		s += "Fields:"+System.getProperty("line.separator");
		for(NodeField field: getFields()) {
			s += "    - " + field.getType() + " " + field.getFieldname()+ ": "+ field.getValue()+System.getProperty("line.separator");
		}
		s += "OrderIds:";
//		for(String lines: getLines()) {
//			s += " " +lines;
//		}
		s += System.getProperty("line.separator");
		return s;
	}
	@Override
	public boolean equals(Object object) {
		if(object instanceof Node) {
			return equals((Node)object);
		}
		else {
			return super.equals(object);
		}
	}
	public boolean equals(Node node) {
		return node.getId().equals(this.getId());
	}

	public String getReturnType() {
		return methodReturnType;
	}

	public void setReturnType(String returnType) {
		this.methodReturnType = returnType;
	}

	public boolean isStackFrameMethod() {
		return isStackFrameMethod;
	}

	public void setStackFrameMethod(boolean isStackFrameMethod) {
		this.isStackFrameMethod = isStackFrameMethod;
	}

	public boolean isStaticMethod() {
		return isStaticMethod;
	}

	public void setStaticMethod(boolean isStatic) {
		this.isStaticMethod = isStatic;
	}
	
}